import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
import { TagsService } from './tags.service';
import { CreateTagDto } from './dto/create-tag.dto';
import { UpdateTagDto } from './dto/update-tag.dto';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
import { QueryDto } from './dto/query.dto';

@Controller('tags')
export class TagsController {
  constructor(private readonly tagsService: TagsService) {}

  @Post()
  @ApiOperation(
    {
        summary: 'Create a tag',
        description: 'Create a tag',
    }
  )
  @ApiResponse(
    {
        status: 201,
        description: 'The tag has been successfully created',
        type: CreateTagDto
    }
  )
  create(@Body() createTagDto: CreateTagDto) {
    return this.tagsService.create(createTagDto);
  }

  @Get()
  @ApiOperation(
    {
        summary: 'Get all tags',
        description: 'Get all tags',
    }
  )
  @ApiResponse(
    {
        status: 200,
        description: 'The all tags has been successfully getted',
        type: [UpdateTagDto]
    }
  )
  findAll(@Query() query: QueryDto) {
    console.log(query, 'get query')
    return this.tagsService.findAll(query);
  }

  @Get(':id')
  @ApiOperation(
    {
        summary: 'Get a tag',
        description: 'Get a tag',
    }
  )
  @ApiResponse(
    {
        status: 200,
        description: 'The tag has been successfully getted',
        type: UpdateTagDto
    }
  )
  findOne(@Param('id') id: number) {
    return this.tagsService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation(
    {
        summary: 'The tag has been successfully updated',
        description: 'The tag has been successfully updated',
    }
  )
  @ApiResponse(
    {
        status: 200,
        description: 'The tag has been successfully updated',
        type: UpdateTagDto
    }
  )
  update(@Param('id') id: string,@Body() updateTagDto: UpdateTagDto) {
    return this.tagsService.update(+id, updateTagDto);
  }

  @Delete(':id')
  @ApiOperation(
    {
        summary: 'The tag has been successfully deleted',
        description: 'The tag has been successfully deleted',
    }
  )
  @ApiResponse(
    {
        status: 200,
        description: 'The tag has been successfully deleted',
        type: UpdateTagDto
    }
  )
  remove(@Param('id') id: string) {
    return this.tagsService.remove(+id);
  }
}
